<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0,user-scalable=no,minimal-ui">
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="icon" href="../img/asset-favico.ico">
    <title>个人中心</title>
    <link rel="stylesheet" href="../css/page-health-orderInfo.css"/>
    <link rel="stylesheet" href="../plugins/elementui/index.css"/>
    <script src="../plugins/jquery/dist/jquery.min.js"></script>
    <script src="../plugins/healthmobile.js"></script>
    <script src="../plugins/datapicker/datePicker.js"></script>
    <script src="../plugins/vue/vue.js"></script>
    <script src="../plugins/vue/axios-0.18.0.js"></script>
    <script src="../plugins/elementui/index.js"></script>
    <script>
        var id = getUrlParam("id");
    </script>
</head>

<body data-spy="scroll" data-target="#myNavbar" data-offset="100">
    <div id="app" class="app">
        <!-- 页面头部 -->
        <div class="top-header">
            <span class="f-left"><i class="icon-back" onclick="history.go(-1)">返回</i></span>
            <span class="center">个人中心</span>
            <span class="f-right"><i class="icon-more"></i></span>
        </div>
        <!-- 页面内容 -->
        <div class="contentBox">
            <div class="form-info">
                <div class="info-title">
                    <span class="name">信息详情</span>
                </div>

                <form class="info-form">
                    <div class="input-row">
                        <label>用户名</label>
                        <input v-model="orderInfo.name" type="text" class="input-clear" placeholder="请输入姓名">
                    </div>

                    <div class="input-row single-radio">
                        <label class="radio-title">性别</label>
                        <div class="radio-list">
                            <div class="radio">
                                <input v-model="orderInfo.sex" id="item1" type="radio" name="sex" value="1" checked>
                                <label for="item1"></label>
                                <span>男</span>
                            </div>

                            <div class="radio">
                                <input v-model="orderInfo.sex" id="item2" type="radio" name="sex" value="2">
                                <label for="item2"></label>
                                <span>女</span>
                            </div>
                        </div>
                    </div>

                    <div class="input-row">
                        <label>年龄</label>
                        <input v-model="orderInfo.age" type="text" class="input-clear" placeholder="请输入年龄">
                    </div>

                    <div class="input-row">
                        <label>手机号</label>
                        <input v-model="orderInfo.phoneNumber" type="text" class="input-clear" placeholder="请输入手机号">
                    </div>

                    <div class="input-row">
                        <label>身份证号码</label>
                        <input v-model="orderInfo.idCard" type="text" class="input-clear" placeholder="请输入身份证号">
                    </div>

                    <div class="input-row">
                        <label>生日</label>
                        <input v-model="orderInfo.birthday" type="text" class="input-clear" placeholder="请输入出生日期">
                    </div>

                    <div class="input-row">
                        <label>邮箱</label>
                        <input v-model="orderInfo.email" type="text" class="input-clear" placeholder="请输入邮箱">
                    </div>

                    <div class="input-row">
                        <label>注册日期</label>
                        <input v-model="orderInfo.regTime" type="text" class="input-clear" placeholder="请输入注册日期" onfocus="this.blur()">
                    </div>
                </form>

                <div class="box-button">
                    <button @click="submitOrder()" type="button" class="btn order-btn">修改个人信息</button>
                </div>
            </div>
        </div>
    </div>

    <script>
        // 格式化时间的方法
        function dateFormat(fmt, date) {
            let ret;
            const opt = {
                "Y+": date.getFullYear().toString(),        // 年
                "m+": (date.getMonth() + 1).toString(),     // 月
                "d+": date.getDate().toString(),            // 日
                "H+": date.getHours().toString(),           // 时
                "M+": date.getMinutes().toString(),         // 分
                "S+": date.getSeconds().toString()          // 秒
                // 有其他格式化字符需求可以继续添加，必须转化成字符串
            };
            for (let k in opt) {
                ret = new RegExp("(" + k + ")").exec(fmt);
                if (ret) {
                    fmt = fmt.replace(ret[1], (ret[1].length == 1) ? (opt[k]) : (opt[k].padStart(ret[1].length, "0")))
                }
                ;
            }
            ;
            return fmt;
        }

        // 更新个人信息-校验方式
        var vue = new Vue({
            el: '#app',
            data: {
                setmeal: {},
                orderInfo: {
                    setmealId: id,
                    sex: '1'
                }
            },

            // 钩子函数
            mounted: function () {
                axios.post("/personalCenter/findMemberByRedis.do").then((res) => {
                    if (res.data.flag) {
                        this.orderInfo = res.data.data;
                        var date = new Date(this.orderInfo.birthday);
                        var birthday = dateFormat("YYYY-mm-dd",date);
                        this.orderInfo.birthday = birthday;

                        var date1 = new Date(this.orderInfo.regTime);
                        var regTime = dateFormat("YYYY-mm-dd",date1);
                        this.orderInfo.regTime = regTime;
                    }
                })
            },

            methods: {
                // 发送验证码-校验手机号
                sendValidateCode() {
                    // 双向绑定, 可以通过 this.orderInfo.telephone 获取到用户输入的手机号
                    var telephone = this.orderInfo.telephone;
                    // 正则表达式进行判断 checkTelephone
                    if (!checkTelephone(telephone)) {
                        this.$message.error("请输入正确的手机号");
                        return false;
                    }
                },
                // 更新个人信息校验方式
                submitOrder() {
                    // 更新个人信息-校验手机号码
                    var telephone = this.orderInfo.phoneNumber;// 双向绑定, 可以通过 this.orderInfo.telephone 获取到用户输入的手机号
                    // 正则表达式进行判断 checkTelephone
                    if (!checkTelephone(telephone)) {
                        this.$message.error("请输入正确的手机号");
                        return false;
                    }
                    // 更新个人信息-校验身份证号
                    var idCard = this.orderInfo.idCard;
                    if (!checkIdCard(idCard)) {
                        // 不合法
                        this.$message.error("身份证号码输入错误，请重新输入");
                        return false;
                    }
                    axios.post("/personalCenter/updatePersonalData.do", this.orderInfo).then((res) => {
                        if (res.data.flag) {
                            this.$message.success(res.data.message);
                        } else {
                            //修改失败，提示信息
                            this.$message.error(res.data.message);
                        }
                    })
                }
            },
        });
    </script>
</body>
</html>